Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per Request Cache #681

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Per Request Cache #681

wants to merge 9 commits into from

Conversation

gkmk
Copy link

@gkmk gkmk commented Aug 6, 2024

This would allow for in memory caching instead of pinging the "real" cache store each time. Noticed large number of requests when using Laravel Nova with Laratrust. When Nova is checking the policies (which check user permissions and roles) it makes 100+ requests which is unnecessary for single request.

Before

image
image

After

image
image

Captures from Laravel Telescope

gkmk added 9 commits August 6, 2024 12:44
Add another layer of in memory cache. Avoids pinging the "real" cache for the same request.
Same as with UserDefaultChecker, it avoids pinging the real cache multiple times for the same request.
Update RoleDefaultChecker.php
@santigarcor
Copy link
Owner

I have a question, it's wrapping the whole logic with array driver cache, so it's basically loading the data in memory for the whole request, so it only hits the real cache once per request, is that right?

@gkmk
Copy link
Author

gkmk commented Jan 15, 2025

I have a question, it's wrapping the whole logic with array driver cache, so it's basically loading the data in memory for the whole request, so it only hits the real cache once per request, is that right?

Thats correct.

Even better solution might be the Laravel Once helper
However i dont know which version of laravel it was introduced into so its not really backward compatible.

@santigarcor
Copy link
Owner

Yes, the once helper was introduced in version 11.X. I believe there is an issue with your approach, if we run this in a worker, the permissions will be cached "forever" until they are restarted.

@gkmk
Copy link
Author

gkmk commented Jan 16, 2025

Interesting, i am using Vapor serverless so havent even thought of something like that. Have you verified that the array cache persists between queue jobs on same worker?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants